package com.yb.nowcoder;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * 华为机试练习第5题
 */
public class Main13 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int size = in.nextInt();
            Integer head = in.nextInt();
            List<Integer> list = new LinkedList<>();
            list.add(head);
            for (int i = 0; i < size - 1; i++) {
                Integer node1 = in.nextInt();
                Integer node2 = in.nextInt();
                if (list.contains(node1)) {
                    continue;
                }
                int idx = list.indexOf(node2);
                if (idx == -1) {
                    continue;
                }
                list.add(idx + 1, node1);

            }
            Integer delValue = in.nextInt();
            list.remove(delValue);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i) + " ");
            }
            System.out.println(sb.toString());
        }
    }
}
